package com.service;

import com.bean.Subsidy;
import com.dao.ISubsidyManagementDao;
import com.dao.SubsidyManagementDaoImp;

import java.util.Arrays;
import java.util.List;

public class SubsidyManagementServiceImp implements ISubsidyManagementService {

    private ISubsidyManagementDao subsidyManagementDao = new SubsidyManagementDaoImp();

    /**
     *
     * @param subsidyProjectName 需要查询的项目名称
     * @return 将查询到名称一致的项目的列表转换为的Subsidy数组，便于传递给前端
     */
    @Override
    public Subsidy[] SearchSubsidyByName(String subsidyProjectName) {
        return subsidyManagementDao.SearchSubsidyByName(subsidyProjectName);
    }

    /**
     * 一个将subsidy的页面数据填入数据库的服务
     *
     * @param subsidy servlet获取到的页面数据
     * @return 是否添加成功
     */
    @Override
    public boolean addSubsidy(Subsidy subsidy) {
        return subsidyManagementDao.addSubsidy(subsidy);
    }

    /**
     * @param idStr 想要切换的项目id
     * @return 切换成功或失败
     */
    @Override
    public boolean switchSubsidyById(String idStr, String flagStr) {
        boolean flag = Boolean.parseBoolean(flagStr);
        int id = Integer.parseInt(idStr);

        System.out.println(flag);
        System.out.println(id);

        if(flag)
        {
            return subsidyManagementDao.stopSubsidyById(id);
        }

        return subsidyManagementDao.startSubsidyById(id);
    }

    /**
     * @param idStr 想要删除的id
     * @return 删除成功或失败
     */
    @Override
    public boolean delSubsidyById(String idStr) {
        return subsidyManagementDao.delSubsidyById(Integer.parseInt(idStr));
    }

    /**
     *
     * @param subsidy
     * @return
     */
    @Override
    public boolean reviseSubsidy(Subsidy subsidy) {
        return subsidyManagementDao.reviseSubsidy(subsidy);
    }

}
